#region Using Directives

using System;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.CSharp.Stages;

#endregion

namespace CCN.StyleCopPlugin
{
    /// <summary>
    /// Daemon stage for <c>StyleCop</c> analysis. This class is automatically loaded by <see cref="JetBrains.ReSharper"/> daemon 
    /// because it's marked with the attribute.
    /// </summary>
    [DaemonStage(StagesBefore = new[] {
                                          typeof(GlobalErrorStage)
                                      },
        StagesAfter = new[] {
                                typeof(LanguageSpecificDaemonStage)
                            }, RunForInvisibleDocument = true)]
    public class StyleCopDaemonStage : CSharpDaemonStageBase
    {
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document
        /// </summary>
        /// <param name="process"></param>
        /// <returns>
        /// Code analysis process to be executed or <c>null</c> if this stage is not available for this file.
        /// </returns>
        /// <exception cref="ArgumentNullException"><c>process</c> is null.</exception>
        public override IDaemonStageProcess CreateProcess(IDaemonProcess process)
        {
            if(process == null)
            {
                throw new ArgumentNullException("process");
            }

            if(!IsSupported(process.ProjectFile))
            {
                return null;
            }
            return new StyleCopDaemonStageProcess(process);
        }


        /// <summary>
        /// Check the error stripe indicator necessity for this stage after processing given <paramref name="projectFile"/>
        /// </summary>
        /// <param name="projectFile"></param>
        /// <returns></returns>
        public override ErrorStripeRequest NeedsErrorStripe(IProjectFile projectFile)
        {
            // We want to add markers to the right-side stripe as well as contribute to document errors
            return ErrorStripeRequest.STRIPE_AND_ERRORS;
        }
    }
}